package org.cb.core;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import org.cb.client.Client;
import org.cb.gui.MainGUI;

/**
 * 
 * @author Fsig
 * 
 * Listen to the mouse events outside of our JFrame.
 * 
 * With that information use the X,Y cords to create
 * a buffered image that we can read our colour values
 * from.
 *
 */
public class Listener implements MouseListener {
	
	public Listener(){
		Client.applet.addMouseListener(this);
		System.out.println("Added listener...");
	}
	
	public void update(){
		Client.applet.getComponentAt(1, 1).removeMouseListener(this);
		Client.applet.getComponentAt(1, 1).addMouseListener(this);
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		if(Global.isReadyToGetColour()){
			try {
				//int newx = MouseInfo.getPointerInfo().getLocation().x - (Global.getMainGUIx() - Global.getRs_panex()) -10;
				//int newy = MouseInfo.getPointerInfo().getLocation().y - (Global.getMainGUIy() - Global.getRs_paney()) -78;
				
				MainGUI.log("Colour At Mouse: " + ColourBot.getColor(Global.getTheMouse().mouseXY) + 
						" - Mouse Loc X,Y: " + Global.getTheMouse().mouseXY);
			} catch (Exception e1){e1.printStackTrace();}
		}
	}

	public void mouseEntered(MouseEvent e) {}
	public void mouseExited(MouseEvent e) {}
	public void mousePressed(MouseEvent e) {}
	public void mouseReleased(MouseEvent e) {}
}
